home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #12 / Amiga Plus CD - 2002 - No. 12.iso / Tools / Freeware / ttengine-5.0 / Examples / MoreFonts / morefonts.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-05  |  5.1 KB  |  151 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11.  
  12. #include <libraries/ttengine.h>
  13.  
  14. extern struct Library *SysBase, *DOSBase;
  15. STRPTR fontname;
  16.  
  17. /*----------------------------------------------------------------------------------------------------*/
  18.  
  19. static STRPTR get_font_name(struct Library *AslBase, ULONG num)
  20.   {
  21.     struct FileRequester *freq;
  22.     STRPTR name = NULL;
  23.     UBYTE title[28];
  24.  
  25.     sprintf(title, "Select %ld TrueType font", num);
  26.  
  27.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  28.       {
  29.         if (AslRequestTags(freq,
  30.           ASLFR_TitleText, (ULONG)"haha",
  31.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  32.           ASLFR_DoPatterns, TRUE,
  33.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  34.           ASLFR_RejectIcons, TRUE,
  35.           TAG_END))
  36.           {
  37.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  38.  
  39.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  40.               {
  41.                 strncpy(name, freq->fr_Drawer, namelen);
  42.                 AddPart(name, freq->fr_File, namelen);
  43.               }
  44.           }
  45.         FreeAslRequest(freq);
  46.       }
  47.     return name;
  48.   }
  49.  
  50. /*----------------------------------------------------------------------------------------------------*/
  51.  
  52. static VOID free_font_name(STRPTR name)
  53.   {
  54.     if (name) FreeVec(name);
  55.   }
  56.  
  57. /*----------------------------------------------------------------------------------------------------*/
  58.  
  59. #define NFN 4
  60.  
  61. int Main (void)
  62.   {
  63.     struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase;
  64.     struct Window *win;
  65.     APTR fonts[NFN];
  66.     WORD i;
  67.     ULONG sigmask, signals;
  68.     BOOL running = TRUE;
  69.  
  70.     if (GfxBase = OpenLibrary("graphics.library", 39))
  71.       {
  72.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  73.           {
  74.             if (AslBase = OpenLibrary("asl.library", 38))
  75.               {
  76.                 if (TTEngineBase = OpenLibrary("ttengine.library", 4))
  77.                   {
  78.                     if (win = OpenWindowTags(NULL,
  79.                       WA_Top, 25,
  80.                       WA_Left, 0,
  81.                       WA_Width, 550,
  82.                       WA_Height, 150,
  83.                       WA_CloseGadget, TRUE,
  84.                       WA_DragBar, TRUE,
  85.                       WA_DepthGadget, TRUE,
  86.                       WA_IDCMP, IDCMP_CLOSEWINDOW,
  87.                       WA_Title, (ULONG)"TTEngine test - 4 fonts at once",
  88.                       TAG_END))
  89.                       {
  90.                         struct RastPort *rp = win->RPort;
  91.  
  92.                         for (i = 1; i <= NFN; i++)
  93.                           {
  94.                             if (!(fonts[i - 1] = TT_OpenFont(
  95.                               TT_FontFile, (ULONG)fontname = get_font_name(AslBase, i),
  96.                               TT_FontSize, 18,
  97.                             TAG_END)))
  98.                               {
  99.                                 PutStr("TT_OpenFont failed!\n");
  100.                               }
  101.                             else Printf("Font %ld @ $%08lx\n", i, (ULONG)fonts[i - 1]);
  102.                             free_font_name(fontname);
  103.                           }
  104.  
  105.                         SetDrMd(rp, JAM1);
  106.                         SetAPen(rp, 2);
  107.                         TT_SetAttrs(rp, TT_Window, (ULONG)win);
  108.  
  109.                         for (i = 1; i <= NFN; i++)
  110.                           {
  111.                             Printf("Font %ld at $%08lx\n", i, (ULONG)fonts[i - 1]);
  112.  
  113.                             if (TT_SetFont(rp, fonts[i - 1]))
  114.                               {
  115.                                 Move(rp, 10, 20 + i * 18);
  116.                                 TT_Text(rp, "Text rendered with one of four TrueType fonts.", 46);
  117.                               }
  118.                           }
  119.  
  120.                         for (i = 1; i <= NFN; i++) if (fonts[i]) TT_CloseFont(fonts[i - 1]);
  121.  
  122.                         sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  123.                         while (running)
  124.                           {
  125.                             signals = Wait(sigmask);
  126.                             if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  127.                             if (signals & (1 << win->UserPort->mp_SigBit))
  128.                               {
  129.                                 struct IntuiMessage *imsg;
  130.  
  131.                                 while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  132.                                   {
  133.                                     if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  134.                                     ReplyMsg((struct Message*)imsg);
  135.                                   }
  136.                               }
  137.                           }
  138.                         TT_DoneRastPort(rp);
  139.                         CloseWindow(win);
  140.                       }
  141.                     CloseLibrary(TTEngineBase);
  142.                   }
  143.                 CloseLibrary(AslBase);
  144.               }
  145.             CloseLibrary(IntuitionBase);
  146.           }
  147.         CloseLibrary(GfxBase);
  148.       }
  149.     return 0;
  150.   }
  151.